<?php

class PublicController extends Controller
{
	public function init()
	{
		C('LAYOUT',false);
	}
	public function loginAction()
	{
		if (IS_POST){
			session_start();
			$email=$_POST['username'];
			$password=$_POST['password'];
			$verify=$_POST['verifycode'];
			if ($verify==$_SESSION['verify']){
				$res=M('user')->field('id,username,password')->where(array('username'=>$email,'status'=>1))->find();
				
				if ($res && $res['password']===$password){
					//登录成功
					$_SESSION['admin']['username']=$res['username'];
					$_SESSION['admin']['userid']=$res['id'];
					M('user')->setLoginStatus($res);
					$this->success('登录成功',U('Admin.Index.index'));
					
				}else{
					$this->error('帐号和密码输入错误');
				}
			}else{
				$this->error('验证码输入错误');
			}
		}
		$this->display();
	}

	public function loginoutAction()
	{
		session_start();
		$_SESSION['admin']=null;
		$this->redirect(U('Admin.Index.index'));
	}
}